
#ifndef __REGEXP_H__
#define __REGEXP_H__

#include "automata.h"

typedef struct
{
    char *exp;
    int pos;
    int n;
    t_table *t;
    
    int numStates;
    int lastState;
    
    int iniState;
    int finState;
    
    int err;
    int errPos;
    
} RegExpInfo;

typedef enum
{
    NONE,
    ASTERISK,
    PLUS
  
} ModType;

char *modNames[] = {"NONE", "ASTERISK", "PLUS"};

typedef struct
{
    int in;
    int out;

} RexBlock;


// Logs a message marking the position of the
// last error in the regular expression
void MarkError(void);


// Sets the regular expression to work with
void SetRegExp(char *exp);

// Translates the current regular expression into an automaton
t_table *TranslateRegExp(void);


// Processes "terms" (OR-wise)
RexBlock getTerms(void);

// Processes "factors" (concatenation-wise)
RexBlock getFactors(void);

// Consume * and + modifiers. Cancel if there's more than one
ModType getMods(void);


// Add building blocks

RexBlock addLambdaBlock(void);
RexBlock addSymbolBlock(char symbol);
RexBlock addSplitBlock(RexBlock b1, RexBlock b2);
RexBlock addConcatBlock(RexBlock b1, RexBlock b2);
RexBlock addWrapperBlock(RexBlock b1);
int addBlockModifier(RexBlock b, ModType m);


// Initializes automaton for processing
void initAutomaton(void);

// Leaves automaton ready for the following stages
void fixAutomaton(void);

// deprecated
//int getNewState(void);

// 
void LogTable(t_table * t, char *name);

#endif
